<?php
class comment
{
	public function get_all_by_article_id($article_id)
	{
		$comment_path = Kohana::config('core.comment_data_path');
		$comments = array();
		if(file_exists($comment_path.$article_id))
		{
			$comments = glob($comment_path.$article_id."/*.comment");
			if($comments)
			{
				natsort($comments);
				//$comments = array_reverse($comments);
				$comments_arr = array();
				foreach($comments as $i=>$comment)
				{
					$comments_arr[$i] = self::get_detail($comment);
				}
				$comments = $comments_arr;
			}
		}
		return $comments;
	}

	public static function get_detail($comment_file)
	{
		$content = explode(PHP_EOL,file_get_contents($comment_file),2);
		$meta = explode('|',$content[0]);
		$comment = array();
		$comment['email'] = $meta[0];
		$comment['pubdate'] = $meta[1];
		$comment['content'] = $content[1];
		$comment['comment_id'] = pathinfo($comment_file,PATHINFO_FILENAME);
		return $comment;
	}
}
